package cn.gson.springboot.common;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import cn.gson.springboot.model.pojos.User;


public class InterceptorConfig  implements HandlerInterceptor{  
	  
    //private static final Logger log = LoggerFactory.getLogger(InterceptorConfig.class);  
  
    /** 
     * 进入controller层之前拦截请求 
     * @param httpServletRequest 
     * @param httpServletResponse 
     * @param o 
     * @return 
     * @throws Exception 
     */  
    @Override  
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 
    	
    	HttpSession session =request.getSession();
	    User user= (User) session.getAttribute("user");	   
		if(user!=null) {
			 return true;
		}else {
			String url="denglu";
			response.sendRedirect(url);
			return false;
		}
  
    }  
  
    @Override  
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler, ModelAndView modelAndView) throws Exception {  
        //log.info("--------------处理请求完成后视图渲染之前的处理操作---------------");  
    }  
  
    @Override  
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler, Exception e) throws Exception {  
        //log.info("---------------视图渲染之后的操作-------------------------0");  
    }  
}  